package com.geek.water.job;

import lombok.extern.slf4j.Slf4j;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author chenmin
 * @desc TODO
 * @date 2025/8/6
 */
@Configuration  // 取消注释，启用配置类
@Slf4j
public class QuartZConfig {

    // 任务明细
    @Bean  // 取消注释
    public JobDetail jobDetail() {
        return JobBuilder.newJob(CleanImgJob.class)
                .storeDurably()  // 持久化任务
                .build();
    }

    // 触发器
    @Bean  // 取消注释
    public Trigger trigger() {
        // 修改为每天凌晨3点执行 (0 0 3 * * ?)
        CronScheduleBuilder schedule = CronScheduleBuilder.cronSchedule("0 0 3 * * ?");
        return TriggerBuilder.newTrigger()
                .forJob(jobDetail())  // 关联任务
                .withSchedule(schedule)
                .build();
    }
}
